package com.yueqian.system.controller;


import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.*;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yueqian.framework.entity.ResultEntity;
import com.yueqian.system.converter.DeptConvert;
import com.yueqian.system.entity.Dept;
import com.yueqian.system.service.DeptService;
import com.yueqian.system.vo.req.DeptReqVO;
import com.yueqian.system.vo.res.DeptResVO;


@RestController
@RequestMapping("/dept")
public class DeptController {

	@Resource
	private DeptService deptService;

	@GetMapping("/selectPageData")
	public ResultEntity<Page<DeptResVO>> selectPage(DeptReqVO reqVO) {
		Page<Dept> deptIPage = deptService.selectPageData(reqVO);
		Page<DeptResVO> deptResVOIPage = DeptConvert.INSTANCE.toPage(deptIPage);
		return ResultEntity.success(deptResVOIPage);
	}

	@GetMapping("/selectListData")
	public ResultEntity<List<DeptResVO>> selectListData(DeptReqVO reqVO) {
		return ResultEntity.success(deptService.selectListData(reqVO));
	}

	@GetMapping("/getDetail")
	public ResultEntity<DeptResVO> getDetail(@RequestParam(value = "id", required = false) Long id) {
		DeptResVO deptResVO = deptService.getDetail(id);
		return ResultEntity.success(deptResVO);
	}

	@PostMapping("/add")
	public ResultEntity<Long> add(@RequestBody DeptReqVO reqVO) {
		return ResultEntity.success(deptService.add(reqVO));
	}

	@GetMapping("/delete")
	public ResultEntity<Long> delete(@RequestParam(value = "id") Long id) {
		return ResultEntity.success(deptService.delete(id));
	}
}
